//
//  LoginService.swift
//  HR
//
//  Created by zhenyu on 17/6/25.
//  Copyright © 2017年 allblue. All rights reserved.
//

import Foundation

class loginService {
  
  
  /// 判断是否登录
  ///
  /// - Parameter login: 已登录操作
  static func check(login: (()->())?) {
    guard User.token != "" else {
      show()
      return
    }
    login?()
  }
  
  /// present 登录
  static func show() {
    
    var vc: NavigationController!
    var targetVC: ViewController!
    
    targetVC = LoginViewController()
    vc = NavigationController(rootViewController: targetVC)
    vc.navigationBar.setBackgroundImage(UIImage.imageWithColor(color: UIColor.white), for: .default)
    vc.navigationBar.barTintColor = Color.font
    vc.navigationBar.tintColor = Color.font
    vc.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: Color.font]
    vc.isNormal = false
    
    _ = UIButton().then {
      $0.frame = CGRect(x: 0, y: 0, width: 100, height: 40)
//      $0.titleEdgeInsets.left = -70
      $0.imageEdgeInsets.left = -70
      $0.setImage(#imageLiteral(resourceName: "l_close"), for: .normal)
      $0.addTarget(targetVC, action: #selector(ViewController.dimiss), for: .touchUpInside)
      vc.topViewController?.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: $0)
    }
    
    Transition.present(vc: vc, completion: nil)
  }
}
